<template>
  <div>
    <div class='goodlist'>
    <div @click="toGoodInfo(item.id)" v-for="item in goodlist" :key="item.id" class='good'>
      <img :src="item.img_url" />
      <div class="tit">{{item.title}}</div>
      <div class="goodprice">
        <span class="price">￥{{item.sell_price}}</span>
        <span class="no">￥{{item.market_price}}</span>
        <div class="infoBtn">
            <div>热卖中</div>
          <div>剩余{{item.stock_quantity}}件</div>
        </div>
      </div>
    </div>
  </div>
    <mt-button style =' margin-bottom:10px' type="danger" v-if="more" size="large" @click='chickMore()'>加载更多</mt-button>
    <p v-else>没有更多了哦！</p>
  </div>
</template>

<script>
import {api} from '@/common/api'
export default {
  data () {
    return {
      goodlist: [],
      pageindex: 1,
      more: true
    }
  },
  created () {
    this.getGoodList()
  },
  methods: {
    getGoodList () {
      this.$axios.get(`${api}getgoods?pageindex=${this.pageindex}`).then(res => {
        this.more = !!res.data.message.length
        this.goodlist = this.goodlist.concat(res.data.message)
      })
    },
    chickMore () {
      this.pageindex += 1
      this.getGoodList()
    },
    toGoodInfo (id) {
      this.$router.push({name: 'goodsinfo', params: {id: id}})
    }
  }
}
</script>

<style lang="scss" scoped>
  .goodlist{
    display: flex;
    flex-wrap: wrap;
    padding: 10px;
    justify-content: space-between;
    .good{
      width: 48%;
      border: 1px solid #eee;
      box-shadow: 0 1px 2px 1px #ccc;
      margin-bottom: 10px;
      min-height: 188px;
      img{
        width: 100%;
        min-height: 0.24784rem;
      }
      .tit{
        font-size: 0.03rem;
        font-weight: 700;
        text-overflow: ellipsis;
      }
      .goodprice{
        margin: 10px 0 15px;
        .price{
          color: red;
          font-weight: 600;
        }
        .no{
          text-decoration: line-through;
        }
      }
      .infoBtn{
        display: flex;
        justify-content: space-between;
      }
    }
  }
</style>
